/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ivanbiz.report;

import com.ivanbiz.model.InternalDelivery;
import com.ivanbiz.model.InternalDeliveryItem;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRParameter;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperPrintManager;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.engine.util.JRLoader;

/**
 *
 * @author Shbt Peterpan
 */
public class InternalDeliveryReport extends CompileReport {

    StringBuilder companyHeader = new StringBuilder();
    StringBuilder companyLogo = new StringBuilder();

    public void printInternalDeliveryItem(List<InternalDeliveryItem> listInternalDeliveryItems, InternalDelivery internalDelivery) {
        InputStream inputStream = null;
        try {
            inputStream = JRLoader.getFileInputStream(System.getProperty("user.dir") + "/report/InternalDeliveryReport.jasper");
            JRDataSource dataSource = new JRBeanCollectionDataSource(listInternalDeliveryItems);
            Map map = new HashMap();
            map.put(JRParameter.REPORT_DATA_SOURCE, dataSource);
            map.put("header", this.getCompanyHeader(companyHeader));
            map.put("logo", this.getCompanyLogo(companyLogo));
            map.put("diskon", new Integer("0"));
            map.put("cabang_kode", internalDelivery.getCabang().getKode());
            map.put("cabang_nama", internalDelivery.getCabang().getNama());
            //map.put("cabang_alamat", internalDelivery.getCabang().getAlamat());
            map.put("tglKirim", internalDelivery.getTanggalKirim());
            map.put("userCreated", internalDelivery.getCreatedBy());
            map.put("userApproved", internalDelivery.getApprovedBy());
            JasperPrint report = JasperFillManager.fillReport(inputStream, map);
            JasperPrintManager.printReport(report, false);
            //JasperViewer.viewReport(report);
        } catch (JRException ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());
            Logger.getLogger(InternalDeliveryReport.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                inputStream.close();
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(null, ex.getMessage());
                Logger.getLogger(InternalDeliveryReport.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}
